package cn.linlane.entity.sys;

import cn.linlane.entity.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@Table(name = "sys_auth")
@Where(clause = "is_delete = false")
public class SysAuth extends BaseEntity {

    @NonNull
    @Column(name = "auth_name")
    @ApiModelProperty(value = "权限名称不能为null")
    private String authName;

    @NonNull
    @Column(name = "auth_code")
    @ApiModelProperty(value = "权限标示不能为null")
    private String authCode;


    @Column(name = "menu_order")
    @ApiModelProperty(value = "排序")
    private String menuOrder;

    @NonNull
    @Column(name = "sys_auth_type")
    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "权限类型, 菜单：MENU, 按钮：BUTTON")
    private SysAuthType sysAuthType;


    @Column(name = "url")
    @ApiModelProperty(value = "页面地址")
    private String url;


    @Column(name = "parent_node_id")
    @ApiModelProperty(value = "父节点ID（上级ID）")
    private Integer parentNodeId;

    @Column(name = "icon")
    @ApiModelProperty(value = "图标")
    private String icon;

    @Transient
    private Set<SysAuth> sysAuths;

    @JsonIgnore
    @ManyToMany(mappedBy = "sysAuths")
    private Set<SysRole> sysRoles;


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + id;
        result = prime * result + ((authCode == null) ? 0 : authCode.hashCode());
        return result;
    }
}
